Skip to content

Detector architecture v2: static engine, benchmarks, lab, and visual contrast#156

Merged
pbakaus merged 25 commits into
mainfrom
codex/detector-v2-speed-visual-contrast
May 18, 2026
Merged

Detector architecture v2: static engine, benchmarks, lab, and visual contrast#156
pbakaus merged 25 commits into
mainfrom
codex/detector-v2-speed-visual-contrast

Conversation

@pbakaus
Copy link
Copy Markdown
Owner

@pbakaus pbakaus commented May 15, 2026

Summary

This PR turns the detector work into a much more explicit architecture, with the speed and inspection tooling needed to keep improving it safely.

Detector architecture

  • Refactors the old detector monolith into focused modules for the registry, shared utilities, pure rule checks, profiling, CLI wiring, source/regex scans, static HTML/CSS scans, browser URL scans, injected browser runtime, and screenshot-based visual contrast.
  • Keeps the public API facade intact through cli/engine/detect-antipatterns.mjs while moving implementation into cli/engine/engines/*, cli/engine/rules/*, cli/engine/shared/*, and cli/engine/browser/injected/*.
  • Updates browser and extension builds to generate from the browser injected entry instead of stripping Node sections out of the old universal file.
  • Moves build-time rule metadata reads to the detector registry instead of scraping the monolithic source file.

Static HTML/CSS engine

  • Replaces the local HTML detection path with a fast static HTML/CSS parser stack: htmlparser2, css-select, css-tree, and domutils.
  • Removes the jsdom-based path and keeps static analysis intentionally layout-free.
  • Preserves detector-needed cascade behavior: linked local stylesheets, @layer flattening, selector matching, specificity/source order, !important, inline styles, variables/fallbacks, inherited typography properties, and needed shorthand expansion.

Browser, visual contrast, and extension behavior

  • Adds createBrowserDetector() for warm browser reuse while keeping one-shot detectUrl() compatibility.
  • Splits pure detection from overlay rendering with window.impeccableDetect() / window.impeccableDetectAsync() and window.impeccableScan() / window.impeccableScanAsync().
  • Adds browser-first visual contrast analysis and pixel-diff screenshot fallback for hard cases like image backgrounds.
  • Adds lazy in-browser visual contrast resolution for offscreen candidates and keeps extension-mode async visual contrast errors visible to the panel.

Benchmarks and detector lab

  • Adds scripts/benchmark-detector.mjs plus bench:detector and bench:detector:browser scripts.
  • Reports per-engine, per-phase, per-rule, per-target timing through the new profiling API.
  • Adds the internal /detector workbench for navigating antipattern fixtures, running scans in an iframe, viewing findings, and seeing timing at a glance.
  • Keeps benchmark output observational only; no hard budgets yet.

Validation

  • bun run test
  • bun run build:browser
  • bun run build:extension
  • bun run build:skills
  • bun run build:site
  • bun run bench:detector -- --quick
  • bun run bench:detector:browser -- --quick
  • git diff --check

Notes

  • Local validation was run outside the sandbox where needed for Puppeteer/headless Chromium and repo build workflows.
  • Rust/Go remains deferred; this branch focuses first on architecture, browser lifecycle, static parser reliability, visual contrast correctness, and measurable performance.

Note

Medium Risk
Large change to the browser detector runtime (overlay lifecycle, extension messaging, async scanning, and optional visual contrast sampling) plus new CLI wiring and dependency swaps; main risk is regressions in scan output/perf across environments and new canvas/CORS edge cases.

Overview
Refactors the browser detector build to be generated from a new injected entry (cli/engine/browser/injected/index.mjs), adding overlay lifecycle management, extension command/error messaging, and new public APIs (impeccableDetect*, impeccableScan*) with optional async scanning.

Adds an in-browser visual contrast analyzer that samples computed backgrounds (including images/gradients via canvas when possible), supports offscreen scanning and lazy resolution via IntersectionObserver, and folds failures into low-contrast findings.

Introduces a new CLI implementation (cli/engine/cli/main.mjs) that supports stdin input, URL scanning with optional browser reuse, directory scanning with import-graph context (importedBy), and user prompts/warnings for large scans, and updates dependencies by removing jsdom in favor of htmlparser2/css-select/css-tree/domutils.

Reviewed by Cursor Bugbot for commit c48b4ab. Bugbot is set up for automated code reviews on this repo. Configure here.

@cloudflare-workers-and-pages
Copy link
Copy Markdown

cloudflare-workers-and-pages Bot commented May 15, 2026

Deploying impeccable with  Cloudflare Pages  Cloudflare Pages

Latest commit: c48b4ab
Status: ✅  Deploy successful!
Preview URL: https://dcee5867.impeccable-2rv.pages.dev
Branch Preview URL: https://codex-detector-v2-speed-visu.impeccable-2rv.pages.dev

View logs

@pbakaus pbakaus marked this pull request as ready for review May 15, 2026 03:04
Comment thread cli/engine/detect-antipatterns-browser.js
Comment thread cli/engine/detect-antipatterns-browser.js Outdated
Comment thread cli/engine/detect-antipatterns-browser.js
Comment thread cli/engine/detect-antipatterns-browser.js
Comment thread cli/engine/detect-antipatterns-browser.js
Comment thread cli/engine/browser/injected/index.mjs Outdated
Comment thread cli/engine/cli/main.mjs
Comment thread cli/engine/detect-antipatterns-browser.js Outdated
@pbakaus pbakaus changed the title [codex] Add detector profiling lab and visual contrast fallback Detector architecture v2: static engine, benchmarks, lab, and visual contrast May 18, 2026
Comment thread cli/engine/cli/main.mjs
Comment thread cli/engine/browser/injected/index.mjs Outdated
Comment thread cli/engine/browser/injected/index.mjs
Comment thread cli/engine/browser/injected/index.mjs
Comment thread cli/engine/detect-antipatterns-browser.js
Comment thread cli/engine/browser/injected/index.mjs
Comment thread cli/engine/browser/injected/index.mjs Outdated
Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 6b15823. Configure here.

Comment thread cli/engine/browser/injected/index.mjs
@pbakaus pbakaus merged commit e1d3ea0 into main May 18, 2026
3 checks passed
@pbakaus pbakaus deleted the codex/detector-v2-speed-visual-contrast branch May 18, 2026 02:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant